home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / nextrad.lha / NeXtRad / wireframe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-22  |  4.2 KB  |  166 lines

  1. /* wireframe.c */
  2.  
  3. /* wireframe package : written by : Jason R. Wilson */
  4. /* last revised : Feb. 21, 1993 */
  5.  
  6. /* provides wireframe support using postscript operators */
  7.  
  8. #include <math.h>
  9. #include <stdio.h>
  10. #import <dpsclient/wraps.h>
  11. #import <appkit/graphics.h>
  12. #include "datastruct.h"
  13. #include "clip.h"
  14.  
  15. Window ViewWindow;
  16. int winWidth;
  17. int winHeight;
  18.  
  19. void InitWire (Window viewwindow,int winwidth,int winheight)
  20.      /* set-up to use wireframe package */
  21. {
  22.   ViewWindow = viewwindow;
  23.   winWidth = winwidth;
  24.   winHeight = winheight;
  25. }
  26.  
  27. void DrawWire(ObjectCell *ObjectHead)
  28. /* when counts gets up over 2000 a stroke and flush are done to keep the
  29.    buffer postscript buffer from overflowing: JRW,  2-2-93 */
  30.  /* draws only patches (not elements */
  31.    
  32. {
  33.    ObjectCell *Object;
  34.    PolygonCell *CurrentPoly;
  35.    VisVertexCell *CurrentVert;
  36.    Homog FirstPoint;
  37.    Boolean Gone;
  38.    double distancex,distancey;
  39.    int count;
  40.    
  41.    distancex = ViewWindow.Wr - ViewWindow.Wl;
  42.    distancey = ViewWindow.Wt - ViewWindow.Wb;
  43.    count = 0;
  44.  
  45.    Object = ObjectHead;
  46.  
  47.    while (!(Object == NULL))
  48.      {
  49.        CurrentPoly = Object->PolygonHead;
  50.        while (!(CurrentPoly == NULL))
  51.      {
  52.        Gone = false;
  53.        ClipPolygon (CurrentPoly,ViewWindow,&Gone);
  54.        if (Gone == false)
  55.          {
  56.            CurrentVert = CurrentPoly->VisVertices;
  57.            FirstPoint = CurrentVert->ViewPosition;
  58.            PSmoveto(rint((FirstPoint.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  59.             rint((FirstPoint.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  60.            count++;
  61.            while (!(CurrentVert->Next == NULL))
  62.          {
  63.            CurrentVert = CurrentVert->Next;
  64.            PSlineto(rint((CurrentVert->ViewPosition.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  65.                 rint((CurrentVert->ViewPosition.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  66.            count++;
  67.          }
  68.            
  69.            PSlineto(rint((FirstPoint.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  70.             rint((FirstPoint.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  71.            count++;
  72.          }
  73.        CurrentPoly = CurrentPoly->Next;
  74.        if (count > 2000)
  75.          {
  76.            count = 0;
  77.            PSsetgray(NX_BLACK);
  78.            PSstroke();
  79.            PSflushgraphics();
  80.          }
  81.      }
  82.        Object = Object->Next;
  83.      }
  84. }
  85.  
  86. /*----------------------------------------------------------------------*/
  87.  
  88. void drawwire(int *count,PolygonCell *CurrentPoly)
  89. /* when counts gets up over 1000 a stroke and flush are done to keep the
  90.    buffer postscript buffer from overflowing: JRW,  2-2-93 */
  91. {
  92.    VisVertexCell *CurrentVert;
  93.    Homog FirstPoint;
  94.    Boolean Gone;
  95.    double distancex,distancey;
  96.    
  97.    distancex = ViewWindow.Wr - ViewWindow.Wl;
  98.    distancey = ViewWindow.Wt - ViewWindow.Wb;
  99.  
  100.    if (CurrentPoly->Subs[0] == NULL)
  101.      { 
  102.        Gone = false;
  103.        ClipPolygon (CurrentPoly,ViewWindow,&Gone);
  104.        if (Gone == false)
  105.      {
  106.        CurrentVert = CurrentPoly->VisVertices;
  107.        FirstPoint = CurrentVert->ViewPosition;
  108.        PSmoveto(rint((FirstPoint.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  109.             rint((FirstPoint.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  110.        (*count)++;
  111.        while (!(CurrentVert->Next == NULL))
  112.          {
  113.            CurrentVert = CurrentVert->Next;
  114.            PSlineto(rint((CurrentVert->ViewPosition.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  115.             rint((CurrentVert->ViewPosition.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  116.            (*count)++;
  117.          }
  118.        
  119.        PSlineto(rint((FirstPoint.hom[0]-ViewWindow.Wl)/(distancex)*winWidth),
  120.             rint((FirstPoint.hom[1]-ViewWindow.Wb)/(distancey)*winHeight));
  121.        (*count)++;
  122.        if ((*count) > 2000)
  123.          {
  124.            (*count) = 0;
  125.            PSsetgray(NX_BLACK);
  126.            PSstroke();
  127.            PSflushgraphics();
  128.          }
  129.      }
  130.      }
  131.    else
  132.      {
  133.        drawwire (count,CurrentPoly->Subs[0]);
  134.        drawwire (count,CurrentPoly->Subs[1]);
  135.        drawwire (count,CurrentPoly->Subs[2]);
  136.        drawwire (count,CurrentPoly->Subs[3]);
  137.      }
  138.  }
  139.  
  140.  
  141. /***********************************************************************/
  142.  
  143. void DrawWireFull (ObjectCell *ObjectHead)
  144. {
  145.   ObjectCell *Object;
  146.   PolygonCell *CurrentPoly;
  147.   int count;
  148.   
  149.   Object = ObjectHead;
  150.   count = 0;
  151.   
  152.   while (!(Object == NULL))
  153.     {
  154.       CurrentPoly = Object->PolygonHead;
  155.       while (!(CurrentPoly == NULL))
  156.     {
  157.       drawwire (&count,CurrentPoly);
  158.       CurrentPoly = CurrentPoly->Next;
  159.     }
  160.       Object = Object->Next;
  161.     }
  162. }
  163.  
  164.  
  165.  
  166.